package com.wzh.musichome.service.impl;

import com.wzh.musichome.entity.pojo.Score;
import com.wzh.musichome.mapper.ScoreMapper;
import com.wzh.musichome.service.ScoreService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 评价 服务实现类
 * </p>
 *
 * @author wzh
 * @since 2020-12-10
 */
@Service
public class ScoreServiceImpl extends ServiceImpl<ScoreMapper,Score> implements ScoreService {




    @Autowired
    private ScoreMapper scoreMapper;


    @Override
    public boolean insert(Score score) {
        return scoreMapper.insert(score)>0;
    }

    @Override
    public int scoreOfSongListId(Integer songListId) {
        int scoreNum = scoreMapper.selectScoreNum(songListId);
        if(scoreNum==0){
            return 5;
        }
        return scoreMapper.selectScoreSum(songListId)/scoreNum;
    }
}
